﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Brjnk.Common.UI">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Common;component/Resources/TreeViewItemCustomStyle.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type local:ObjectPresenter}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ObjectPresenter}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <!--

                        http://leecampbell.blogspot.cz/2009/01/horizontal-stretch-on-treeviewitems.html
                        -->
                        <TreeView Name="PART_TreeView" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemContainerStyle="{StaticResource TreeViewItemCustomStyle}" ItemsSource="{Binding}" HorizontalAlignment="Stretch" AlternationCount="2">
                            <TreeView.ItemTemplate>
                                <HierarchicalDataTemplate ItemsSource="{Binding Children}" AlternationCount="2">
                                    <Border>
                                        <Border.Resources>
                                            <Style TargetType="Border">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TreeViewItem}, Path=(ItemsControl.AlternationIndex)}" Value="1">
                                                        <Setter Property="Border.Background" Value="LightBlue" />
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TreeViewItem}, Path=(ItemsControl.AlternationIndex)}" Value="0">
                                                        <Setter Property="Border.Background" Value="LightGray" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Border.Resources>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"></ColumnDefinition>
                                                <ColumnDefinition Width="*"></ColumnDefinition>
                                                <ColumnDefinition Width="*"></ColumnDefinition>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock FontWeight="Bold" Text="{Binding Name}" />
                                            <TextBlock Grid.Column="1"  Text="{Binding Value}" />
                                            <TextBlock Grid.Column="2"  FontSize="8" Text="{Binding Type}" />
                                        </Grid>
                                    </Border>
                                </HierarchicalDataTemplate>
                            </TreeView.ItemTemplate>
                        </TreeView>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>